<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<!-- Content Header (Page header) -->
<section class="content-header" style="">
    <h1>
        话费管理
        <small>话费管理页面</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
        <li><a href="#">话费管理</a></li>
        <li class="active">话费管理</li>
    </ol>
</section>

<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <!-- /.box-header -->
                <div class="box-body">
                    <div id="toolbar">
                        <form class="form-inline" id="searchForm">
                            <div class="form-group">
                                <label for="searchName">收款人</label>
                                <input type="text" class="form-control input-sm" name="paee" id="searchName" placeholder="请输入店面编号或名称">
                            </div>
                            <div class="form-group">
                                <label for="searchOrgName">收款人</label>
                                <input type="text" class="form-control input-sm" name="orgName" id="searchOrgName" placeholder="请输入店面编号或名称">
                            </div>
                            <div class="btn-group btn-group-sm">
                                <button type="button" class="btn btn-default" onclick="javascript:$('table').bootstrapTable('refresh', {silent: true});">
                                    <i class="glyphicon glyphicon-search"></i>
                                    查询
                                </button>
                                <button type="reset" class="btn btn-default">
                                    <i class="glyphicon glyphicon-trash"></i>
                                    清空
                                </button>
                            </div>
                        </form>
                        <div class="btn-group btn-group-sm">
                            <!-- Provides extra visual weight and identifies the primary action in a set of buttons -->
                            <button shiro:hasPermission="bill:create" type="button" id="addBtn" class="btn btn-default"
                                    data-toggle="modal"
                                    data-target="#addModal"><i class="glyphicon glyphicon-plus"></i> 新增
                            </button>
                            <!-- Indicates caution should be taken with this action -->
                            <button shiro:hasPermission="bill:update" type="button" id="editBtn" class="btn btn-default"
                                    data-toggle="modal"
                                    data-target="#editModal"
                                    data-action="{type:'editable',form:'#editForm',table:'#table',after:'editAfter'}"
                                    disabled><i class="glyphicon glyphicon-edit"></i> 修改
                            </button>
                            <!-- Indicates a dangerous or potentially negative action -->
<!--                            <button shiro:hasPermission="income:delete" type="button" id="deleteBtn" class="btn btn-default" data-toggle="modal"
                                    data-target="#deleteModal"
                                    data-action="{type:'delete',form:'#deleteForm',idField:'id',table:'#table'}"
                                    disabled><i class="glyphicon glyphicon-remove"></i> 删除
                            </button>-->
                        </div>
                    </div>
                    <table id="table"></table>
                </div>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->

        </div>
        <!-- /.col -->
    </div>
    <!-- /.row -->
</section>
<!-- /.content -->
<!-- add Modal -->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="addModalLabel">添加费用</h4>
            </div>
            <div class="modal-body">
                <form id="addForm" >
                    <input type="hidden" id="organizationId" name="organizationId" readonly required>
                    <input type="hidden" id="paeeId" name="paeeId" readonly required>
                    <input type="hidden" id="handlerId" name="handlerId" readonly required>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="datepicker"><span class="asterisk">*</span>交易日期:</label>
                        <div class="col-sm-4">
                            <div class="input-group date">
                                <div class="input-group-addon">
                                    <i class="fa fa-calendar"></i>
                                </div>
                                <input type="text" class="form-control pull-right" id="datepicker" name="billDate">
                            </div>
                            <div class="help-block with-errors"></div>
                        </div>
                            <label class="col-sm-2 control-label" for="handler"><span class="asterisk">*</span>经手人:</label>
                            <div class="col-sm-4">
                                <input id="handler" type="text" class="form-control" name="handler" placeholder="经手人" minlength="1">
                                <div class="help-block with-errors"></div>
                            </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="paee"><span class="asterisk">*</span>收款人:</label>
                        <div class="col-sm-4">
                            <input  type="text" class="form-control" id="paee" name="paee"   placeholder="收款人">
                            <div class="help-block with-errors"></div>
                        </div>
                        <label class="col-sm-2 control-label" for="orgName"><span class="asterisk">*</span>收款门店:</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control typeahead" id="orgName" name="orgName" data-provide="typeahead" placeholder="收款门店" minlength="1">
                            <div class="help-block with-errors"></div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"><span class="asterisk">*</span>费用分类:</label>
                        <div class="col-sm-4">
                            <select class="form-control select" name="catgoryId" required>
                                <option th:each="catgory: ${catgoryList}" th:value="${catgory.id}" th:text="${catgory.name}">费用栏目不存在</option>
                            </select>
                            <div class="help-block with-errors"></div>
                        </div>
                        <label class="col-sm-2 control-label" for="payment"><span class="asterisk">*</span>支出:</label>
                        <div class="col-sm-4">
                            <div class="input-group">
                                <span class="input-group-addon">&yen</span>
                                <input type="text" class="form-control" id="payment"
                                       name="payment" placeholder="支出"
                                       required>
                                <span class="input-group-addon">.00元</span>
                            </div>
                            <div class="help-block with-errors"></div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class=" control-label"><span class="asterisk">*</span>摘要:</label>
                        <textarea class="form-control" id="content" name="content" rows="2" placeholder="摘要 ..." ></textarea>
                        <div class="help-block with-errors"></div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="submit" form="addForm" class="btn btn-primary"
                        data-action="{type:'submit',form:'#addForm',url:'@{/finance/bill/create}',after:'$.myAction.refreshTable'}">
                    确定
                </button>
            </div>
        </div>
    </div>
</div>

<!-- edit Modal -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="editModalLabel">添加费用</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" >
                    <input type="hidden"  name="id" readonly required>
                    <input type="hidden" id="editorganizationId" name="organizationId" readonly required>
                    <input type="hidden" id="editpaeeId" name="paeeId" readonly required>
                    <input type="hidden" id="edithandlerId" name="handlerId" readonly required>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="editdatepicker"><span class="asterisk">*</span>交易日期:</label>
                        <div class="col-sm-4">
                            <div class="input-group date">
                                <div class="input-group-addon">
                                    <i class="fa fa-calendar"></i>
                                </div>
                                <input type="text" class="form-control pull-right" id="editdatepicker" name="billDate">
                            </div>
                            <div class="help-block with-errors"></div>
                        </div>
                        <label class="col-sm-2 control-label" for="edithandler"><span class="asterisk">*</span>经手人:</label>
                        <div class="col-sm-4">
                            <input id="edithandler" type="text" class="form-control" name="handler" placeholder="经手人" minlength="1">
                            <div class="help-block with-errors"></div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="editpaee"><span class="asterisk">*</span>收款人:</label>
                        <div class="col-sm-4">
                            <input  type="text" class="form-control" id="editpaee" name="paee"   placeholder="收款人">
                            <div class="help-block with-errors"></div>
                        </div>
                        <label class="col-sm-2 control-label" for="editorgName"><span class="asterisk">*</span>收款门店:</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control typeahead" id="editorgName" name="orgName" data-provide="typeahead" placeholder="收款门店" minlength="1">
                            <div class="help-block with-errors"></div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"><span class="asterisk">*</span>费用分类:</label>
                        <div class="col-sm-4">
                            <select class="form-control select" name="catgoryId" required>
                                <option th:each="catgory: ${catgoryList}" th:value="${catgory.id}" th:text="${catgory.name}">费用栏目不存在</option>
                            </select>
                            <div class="help-block with-errors"></div>
                        </div>
                        <label class="col-sm-2 control-label" for="editpayment"><span class="asterisk">*</span>支出:</label>
                        <div class="col-sm-4">
                            <div class="input-group">
                                <span class="input-group-addon">&yen</span>
                                <input type="text" class="form-control" id="editpayment"
                                       name="payment" placeholder="支出"
                                       required>
                                <span class="input-group-addon">.00元</span>
                            </div>
                            <div class="help-block with-errors"></div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class=" control-label"><span class="asterisk">*</span>摘要:</label>
                        <textarea class="form-control" id="editcontent" name="content" rows="2" placeholder="摘要 ..." ></textarea>
                        <div class="help-block with-errors"></div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="submit" form="addForm" class="btn btn-primary"
                        data-action="{type:'submit',form:'#editForm',url:'@{/finance/bill/update}',after:'$.myAction.refreshTable'}">
                    确定
                </button>
            </div>
        </div>
    </div>
</div>
<!-- delete modal -->
<!--<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteSmallModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="deleteSmallModalLabel">删除用户</h4>
            </div>
            <div class="modal-body">
                <form id="deleteForm"></form>
                确定要删除选中的 <span class="records"></span> 条记录?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" form="deleteForm" class="btn btn-primary"
                        data-action="{type:'submit',form:'#deleteForm',url:'@{/user/delete}',after:'$.myAction.refreshTable'}">
                    确定
                </button>
            </div>
        </div>
    </div>
</div>-->

<div id="actionButtons" class="admin-hide">
    <a class="like" href="javascript:void(0)" data-toggle="tooltip" title="Like"><i class="glyphicon glyphicon-heart"></i></a>　
    <a class="edit ml10" href="javascript:void(0)" data-toggle="tooltip" title="编辑"><i class="glyphicon glyphicon-edit"></i></a>　
</div>

<script th:inline="javascript">

    var $table = $('#table');

    $(function () {
        // bootstrap table初始化
        // http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/
        $table.bootstrapTable({
            url: CONTEXT_PATH + '/finance/bill/list',
            cache: false,        //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            showExport: true,                     //是否显示导出
            exportDataType: "basic",              //basic', 'all', 'selected'.
            exportTypes: ['excel','xlsx'],                //
            exportOptions:{
                ignoreColumn: [0,1,14]
            },
            idField: 'id',
            columns: [
                {field: 'state', checkbox: true},
                {field: 'id', title: '编号', sortable: true, halign: 'left'},
                {field: 'billDate', title: '交易日期', sortable: true, halign: 'left'},
                {field: 'handler', title: '经手人', sortable: true, halign: 'left'},
                {field: 'paee', title: '收款人', sortable: true, halign: 'left'},
                {field: 'catgoryId', title: '分类', sortable: true, halign: 'left'},
                {field: 'orgName', title: '门店编号', sortable: true, halign: 'left'},
                {field: 'payment', title: '支出', sortable: true, halign: 'left'},
                {field: 'content', title: '摘要', sortable: true, halign: 'left'},
                {
                    field: 'action',
                    title: '操作',
                    halign: 'center',
                    align: 'center',
                    formatter: 'actionFormatter',
                    events: 'actionEvents',
                    clickToSelect: false
                }
            ]
        });
    },

    //Date picker
    $('#datepicker').datepicker({
        autoclose: true,
        format: 'yyyy-MM-dd'
    }),

    //Date picker
    $('#editdatepicker').datepicker({
        autoclose: true,
        format: 'yyyy-MM-dd'
    })
    );
    // 数据表格展开内容
    function detailFormatter(index, row) {
        var html = [];
        $.each(row, function (key, value) {
            html.push('<p><b>' + key + ':</b> ' + value + '</p>');
        });
        return html.join('');
    };

    function actionFormatter(value, row, index) {
          //  console.log("执行了吗？行内修改按钮")
            return $('#actionButtons').html();
        };

    function editAfter(obj, row) {
        //console.log("修改後執行");
        <!--一个用户有几个角色,几个组-->
        /*var roleIdList = row.roleIdList;
        var groupIdList = row.groupIdList;
        for (i in roleIdList) {
            var roleId = roleIdList[i];
            $('#editForm').find('[name=roleIds]').find('option[value=' + roleId + ']').prop('selected', true);
        }
        for(i in groupIdList) {
            var groupId = groupIdList[i];
            $('#editForm').find('[name=groupIds]').find('option[value=' + groupId + ']').prop('selected', true);
        }*/
    };

    window.actionEvents = {
        'click .like': function (e, value, row, index) {
            alert('You click like icon, row: ' + JSON.stringify(row));
            console.log(value, row, index);
        },
        'click .edit': function (e, value, row, index) {
            $('#editModal').modal('show')
            $('#editForm').fillForm(row);
            editAfter('', row);
           // console.log(value, row, index);
        },
        'click .remove': function (e, value, row, index) {
            $('#deleteModal').modal('show');
            $('.records').html('1');
            var html = '';
            for (var key in row) {
                html += '<input type="hidden" name="' + key + '" value="' + row[key] + '">';
            }
            $('#deleteForm').html(html);
        }
    };


            <!--自动填充-->
            //var nameToIdMap = {};//编码对应的id
            var objArray = [];
            var $input = $(".typeahead");
           // console.log("自动填充id="+$input.val())
            $input.typeahead({
                source: function (query, process) {
                    //query是输入的值
                    $.ajax({
                        url: "/wximp/organization/queryByName",
                        async: true,
                        cache: false,
                        type: "GET",
                        dataType: "JSON",
                        data: {name: query},
                        success: function (result) {
                            if (result.code == 200 && result.data) {
                                var array = [];
                                $.each(result.data, function (index, ele) {
                                    objArray.push(Object({
                                        id: ele.id,
                                        shopNo: ele.no,
                                        name: ele.name

                                    }));
                                    array.push(ele.name);
                                    array.push(ele.no);
                                });
                                //alert(JSON.stringify(array));
                                process(array);
                            }
                        }
                    })
                },
                autoSelect: true,
                display: 'name',
                minLength: 2,//键入字数多少开始补全
                showHintOnFocus: "true",//将显示所有匹配项
                fitToElement: true,//选项框宽度与输入框一致
                items: 'all',//下拉选项中出现条目的最大数量。也可以设置为“all”
                forceSerlection: true,////限定选择的值是列表中的 一个
                autoSelect: true,//允许你决定是否自动选择第一个建议
                delay: 500,//在查找之间添加延迟
                afterSelect: function (item) {
                    //遍历对象数组
                    $.each(objArray, function (i, ele) {
                        //console.log("选择="+item+",ele.shoname="+ele.shopNo+"|"+i + "--" + JSON.stringify(ele));
                        if (item == ele.name) {
                            $('#addForm [name="organizationId"]').val(ele.id);

                           /* $('#editForm [name="userId"]').val(ele.id);
                            $("#editphone").val(ele.phone);*/
                        }
                    });
                }
            });

</script>
</html>